﻿using System;
using System.Collections.Generic;
using System.Text;
using Gmmy.RepositoryExtension;
using Surging.Core.CPlatform.Ioc;

namespace Gmmy.RepositoryExtension
{
    public class DataBaseFactory<T> : IDataBaseFactory<T>
        where T: BaseDbContext
    {
        private T _dataContext;
        public DataBaseFactory(T dataContext)
        {
            _dataContext = dataContext;
        }
        public T Get()
        {
            return _dataContext;
        }

        private bool disposed = false;
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    if (_dataContext != null)
                        _dataContext.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}
